﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace SharePointListSync
{
    internal class DataManagerVO
    {
        public string WebMethod { set; get; }
        
        public string WebURL { set; get; }
        public string WebID { set; get; }
        
        public string ListName { set; get; }
        public string ListID { set; get; }

        public string ViewName { set; get; }
        public string ViewID { set; get; }


        public string RowLimit { set; get; }
        public XmlNode ndQueryOptions { set; get; }
        public XmlNode ndQuery { set; get; }
        public XmlNode ndViewFields { set; get; }


        public string strQueryOptions = string.Empty;
        public string strViewFields = string.Empty;
        public string strQuery = string.Empty;

        public bool isInitalizedforEveryWebMethodCalled = false;


        public void resetBeforeUseVO()
        {

            WebMethod = null;

            WebURL = null;
            WebID = null;

            ListName = null;
            ListID = null;

            ViewName = null;
            ViewID = null;


            RowLimit = null;
            ndQueryOptions = null;
            ndQuery = null;
            ndViewFields = null;


            strQueryOptions = string.Empty;
            strViewFields = string.Empty;
            strQuery = string.Empty;
            isInitalizedforEveryWebMethodCalled = false;

        }

        public void InitalizedforEveryWebMethod(string webMethod )
        {
            isInitalizedforEveryWebMethodCalled = true;
            switch (webMethod)
            {

                case "GetListItems":
                    WebMethod = "GetListItems";
                    Prepair_ndQueryOptions();
                    break;

                case "tobefilled":
                    
                    break;

                default:
                    WebMethod = webMethod;
                    break;
            }
        
        
        
        }

        private void Prepair_ndQueryOptions()
        {
           XmlDocument xmlDoc = new XmlDocument();

           if (ndQuery == null)
           {
               ndQuery = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "");
               if (string.IsNullOrEmpty(strQuery))
               {
                   ndQuery.InnerXml = "";
               }
               else
               {
                   ndQuery.InnerXml = strQuery;
               }

           }

           if (ndViewFields == null)
           {

               ndViewFields = xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields", "");


               if (string.IsNullOrEmpty(strViewFields))
               {
                   ndViewFields.InnerXml = "";
               }
               else
               {
                   ndViewFields.InnerXml = strViewFields;
               }
           }

           if (ndQueryOptions == null)
           {
               ndQueryOptions = xmlDoc.CreateNode(XmlNodeType.Element, "QueryOptions", "");

               if (string.IsNullOrEmpty(strQueryOptions))
               {
                   ndQueryOptions.InnerXml ="<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns>";;
               }
               else
               {
                   ndQueryOptions.InnerXml = strQueryOptions;
               }

           }

        }






        



    }
}
